package com.jianan.mis.service;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import com.jianan.mis.data.dao.IntermanDao;
import com.jianan.mis.data.domain.Interman;

public class IntermanServiceImpl implements IntermanService {

	private IntermanDao intermanDao;

	public void save(Interman interman) {
		intermanDao.save(interman);
	}

	public void update(Interman interman) {
		intermanDao.saveOrUpdate(interman);
	}

	public void remove(Interman interman) {
		intermanDao.remove(interman);
	}

	public List<Interman> getAll() {
		return intermanDao.getAll(Interman.class, "Name", true);
	}

	@SuppressWarnings("unchecked")
	public List<Interman> getAllByEmployeeId(Integer employeeId) {
		Criteria criteria = intermanDao.createCriteria(Interman.class);
		criteria.add(Restrictions.eq("Employee.id", employeeId));
		return criteria.list();
	}
	
	public Interman findByName(String name) {
		return intermanDao.findUniqueBy(Interman.class, "Name", name);
	}

	public void setIntermanDao(IntermanDao intermanDao) {
		this.intermanDao = intermanDao;
	}

}
